package cn.wolfcode.wms.util;


import cn.wolfcode.wms.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

//登陆操作中在业务层需要抽取的工具类
public abstract class UserContext {

    public static final String EMP_IN_SESSOIN ="EMP_IN_SESSOIN";
    public static final String EXPS_IN_SESSOIN = "EXPS_IN_SESSOIN";

    private static HttpSession getSession(){

        return ((ServletRequestAttributes)
                (RequestContextHolder.getRequestAttributes())).getRequest().getSession();
    }

    public static void setCurrentUser(Employee e){

        getSession().setAttribute(EMP_IN_SESSOIN,e);
    }
    public static Employee getCurrentUser(){

        return (Employee) getSession().getAttribute(EMP_IN_SESSOIN);
    }

    public static void setExpression(List<String> exps){

        getSession().setAttribute(EXPS_IN_SESSOIN,exps);
    }
    public static List<String> getExpression(){

        return (List<String>) getSession().getAttribute(EXPS_IN_SESSOIN);
    }

}
